#!/usr/bin/env python3

import os
import time

def main():
    print("main start pid = ", os.getpid())
    pid = os.fork()
    if pid == 0:    #子进程要执行的代码
        print("child pid = %d, ppid = %d" % (os.getpid(), os.getppid()))
        time.sleep(1)
        print("child exit....")
        os._exit(244)
    else:           #父进程要执行的代码
        print("main fork end curPid = %d, pid = %d" % (os.getpid(), pid))
        pid, status = os.wait()
        print("child exit pid: ", pid, "child exit status: ", status)
        print("child return data: ", os.WEXITSTATUS(status))
        print("exit: ", os.WIFEXITED(status))
        print("kill: ", os.WIFSIGNALED(status))
        print("main parent end....")

if __name__ == "__main__":
    main()
